package com.hdax.dm.controller;

import com.hdax.dm.common.utils.CommonResponse;
import com.hdax.dm.common.utils.ResponseUtil;
import com.hdax.dm.dtos.item.AreaDto;
import com.hdax.dm.dtos.item.ItemSearchResultDto;
import com.hdax.dm.entity.item.DmItemType;
import com.hdax.dm.service.ItemSearchService;
import com.hdax.dm.vo.ItemSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品搜索控制器
 */
@RestController
@RequestMapping(path = "/item")
public class ItemSearchController {

    @Autowired
    private ItemSearchService itemSearchService;

    /**
     * 根据params查询一、二级分类
     * @return
     */
    @PostMapping(path = "list/sortgoods")
    public CommonResponse<List<DmItemType>> sortgoods(@RequestBody Map<String,Long> param){
        List<DmItemType> itemTypes = itemSearchService.itemTypes(param.get("param") == null ? 0 : param.get("param"));
        return ResponseUtil.returnSuccess(itemTypes);
    }

    /**
     * 查询城市列表信息
     */
    @PostMapping(path = "list/querycity")
    public CommonResponse<List<AreaDto>> querycity(){
        return ResponseUtil.returnSuccess(itemSearchService.queryCities());
    }

    /**
     * 多条件搜索演出剧目（商品）
     * sort:
     * recommend:热门推荐
     * recentShow:最近开场
     * recentSell:最新上架
     */
    @PostMapping(path = "list/querygoodsinfos")
    public CommonResponse<ItemSearchResultDto> querygoodsinfos(@RequestBody ItemSearchVo vo){
        try {
            return ResponseUtil.returnSuccess(itemSearchService.querygoodsinfos(vo));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
